package com.example.controller;

import com.alibaba.fastjson.JSON;
import com.example.model.entity.Account;
import com.example.utils.SignUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author guoQ.z
 * @date 2021/1/13 15:25
 * TODO
 */
@RestController
public class Controller001 {
    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/method001")
    public String method001() {
        Account account = new Account();
        account.setAccountId("101");
        account.setAccountName("101name");
        account.setUserId("user101");
        ModelMap signData = SignUtil.getSignData(account);
        String url = "http://localhost:8080/practice/testKey";
        ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity(url, signData, String.class);
        System.out.println(JSON.toJSONString(stringResponseEntity));
        // 解密
        System.out.println(SignUtil.decryptData(stringResponseEntity.getBody()));
        return stringResponseEntity.getBody();
    }
}
